package com.hnevc.blogsystem;

import java.util.ArrayList;

public class BlogSystem {
	int maxBlogId=1;
	private ArrayList<Blog> blogList;
	private String name;
	
	public BlogSystem() {
		this("网院博客");
	}
	
	public BlogSystem(String name) {
		this.name = name;
		blogList = new ArrayList<>();
	}

	public void setName(String name) {
		this.name = name;
	}
	public void setBlogList(ArrayList<Blog> blogList) {
		this.blogList = blogList;
	}
	public ArrayList<Blog> getBlogList() {
		return blogList;
	}
	public String getName() {
		return name;
	}
	public void addBlog(Blog blog){
		blog.setId(maxBlogId++);
		blogList.add(blog);
	}
	public Blog getBlog(int id){
		for(int i=0;i<blogList.size();i++){
			if(blogList.get(i).getId() ==  id){
				return blogList.get(i);
			}
		}
		return null;
	}
	public void deleteBlog(int id){
		Blog blog = getBlog(id);
		if(blog!=null){
			blogList.remove(blog);
		}
	}
	
	public boolean updateBlog(Blog blog){
		//TODO 完成博文的修改函数
		return true;
	}
	public void showTitles(){
		for(int i=0;i<blogList.size();i++){
			System.out.println(blogList.get(i).getId()+blogList.get(i).getTitle());
		}
	}
	public void showBlog(Blog blog){
		System.out.println("------------------------------");
		System.out.println("id:"+blog.getId());
		System.out.println("title:"+blog.getTitle());
		System.out.println("author:"+blog.getUser().getName());
		System.out.println("content:"+blog.getContent());
		System.out.println("------------------------------");
		
	}
}
